<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/echarts/echarts.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>统计分析
            <small>会员数量</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>统计分析</el-breadcrumb-item>
            <el-breadcrumb-item>会员数量</el-breadcrumb-item>
        </el-breadcrumb>
    </div>

    <!-- <div class="app-container">
         <div class="box">
             <div id="chart1" style="height:600px;"></div>
         </div>
     </div>-->
    <div class="app-container">
        <div class="box">
            <div class="block" :model="memberDate">
                <span class="demonstration">开始时间:</span>
                <el-date-picker
                        v-model="memberDate.startDate"
                        type="month"
                        placeholder="选择日期"
                        value-format="yyyy-MM">
                </el-date-picker>
                <br>
                <span class="demonstration">结束时间:</span>
                <el-date-picker
                        v-model="memberDate.endDate"
                        type="month"
                        placeholder="选择日期"
                        value-format="yyyy-MM">
                </el-date-picker>
                <el-button @click="handleDate()">根据日期展示</el-button>
            </div>
            <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM-->
            <div id="chart2" style="height:600px;"></div>
        </div>
    </div>
</div>
</body>
</html>

<script type="text/javascript">
    var vue = new Vue({
        el:"#app",
        data:{
            memberDate:{
                startDate:'',
                endDate:''
            }
        },
        mounted(){
            this.defaultDate();
        },
        methods:{
            //点击按钮展示数据
            handleDate(){
                var myChart2 = echarts.init(document.getElementById('chart2'));
                axios.post("/report/getMemberReportByDate.do",this.memberDate).then(res=>{
                    if (res.data.data.months=="") {
                        this.$message.error("输入的起始时间有误,没有数据展示");
                        myChart2.setOption({
                            title: {
                                text: '会员数量'
                            },
                            tooltip: {},
                            legend: {
                                data: ['会员数量']
                            },
                            xAxis: {
                                data: [],
                                name:'时间'
                            },
                            yAxis: {
                                name: '会员数量',
                                type: 'value',
                                minInterval : 1
                            },
                            series: [{
                                name: '会员数量',
                                type: 'line',
                                data: []
                            }]
                        });
                    }else {
                        myChart2.setOption({
                            title: {
                                text: '会员数量'
                            },
                            tooltip: {},
                            legend: {
                                data: ['会员数量']
                            },
                            xAxis: {
                                data: res.data.data.months,
                                name:'时间'
                            },
                            yAxis: {
                                name: '会员数量',
                                type: 'value',
                                minInterval : 1
                            },
                            series: [{
                                name: '会员数量',
                                type: 'line',
                                data: res.data.data.memberCount
                            }]
                        });
                    }
                });
            },
            defaultDate(){
                var myChart2 = echarts.init(document.getElementById('chart2'));
                axios.post("/report/getMemberReport.do").then(res=>{
                    //回显默认的12个月日历插件数据
                    this.memberDate.startDate= res.data.data.firstMonth;
                    this.memberDate.endDate= res.data.data.lastMonth;
                    myChart2.setOption({
                        title: {
                            text: '会员数量'
                        },
                        tooltip: {},
                        legend: {
                            data: ['会员数量']
                        },
                        xAxis: {
                            data: res.data.data.months,
                            name:'时间'
                        },
                        yAxis: {
                            name: '会员数量',
                            type: 'value',
                            minInterval : 1
                        },
                        series: [{
                            name: '会员数量',
                            type: 'line',
                            data: res.data.data.memberCount
                        }]
                    });
                });
            }
        }
    });
</script>
